var exp = module.exports;
var dispatcher = require('./dispatcher');

exp.bjl = function (session, msg, app, cb) {
    var gameServers = app.getServersByType('bjl');

    if (!gameServers || gameServers.length === 0) {
        cb(new Error('can not find game servers.'));
        return;
    }

    // console.log('路由： 百家乐： msg: ', JSON.stringify(msg));
    // console.log(msg);
    //
    // if (msg.args[0].route === 'bjl.gameHandler.exiGame') {
    //     msg.args[0].body.exi = 0;
    //     // msg = {
    //     //     namespace: 'sys',
    //     //     serverType: 'bjl',
    //     //     service: 'msgRemote',
    //     //     method: 'forwardMessage',
    //     //     args:
    //     //     [{
    //     //         id: 2,
    //     //         type: 0,
    //     //         compressRoute: 0,
    //     //         route: 'bjl.gameHandler.exiGame',
    //     //         body: [Object],
    //     //         compressGzip: 0
    //     //     },
    //     //     {
    //     //         id: 1,
    //     //         frontendId: 'connector-server-1',
    //     //         uid: '1003',
    //     //         settings: [Object]
    //     //     }]
    //     // };
    // }

    var res = dispatcher.dispatch(session.get('playerId'), gameServers);

    cb(null, res.id);
};

exp.niuniu = function (session, msg, app, cb) {
    var gameServers = app.getServersByType('niuniu');

    if (!gameServers || gameServers.length === 0) {
        cb(new Error('can not find game servers.'));
        return;
    }

    var res = dispatcher.dispatch(session.get('playerId'), gameServers);

    cb(null, res.id);
};

// 疯狂赛车
exp.fksc = function (session, msg, app, cb) {
    var gameServers = app.getServersByType('fksc');

    if (!gameServers || gameServers.length === 0) {
        cb(new Error('can not find game servers.'));
        return;
    }

    var res = dispatcher.dispatch(session.get('playerId'), gameServers);

    cb(null, res.id);
};

// 温州两张
exp.wzlz = function (session, msg, app, cb) {
    var gameServers = app.getServersByType('wzlz');

    if (!gameServers || gameServers.length === 0) {
        cb(new Error('can not find game servers.'));
        return;
    }

    var res = dispatcher.dispatch(session.get('playerId'), gameServers);

    cb(null, res.id);
};

// 二人牛牛
exp.ernn = function (session, msg, app, cb) {
    var gameServers = app.getServersByType('ernn');

    if (!gameServers || gameServers.length === 0) {
        cb(new Error('can not find game servers.'));
        return;
    }

    var res = dispatcher.dispatch(session.get('playerId'), gameServers);

    cb(null, res.id);
};
